package com.DFB.controller;


import com.DFB.common.model.Result;
import com.DFB.pojo.Property;
import com.DFB.service.PropertyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 商品属性表 前端控制器
 * </p>
 *
 * @author DFB
 * @since 2023-09-11
 */
@Slf4j
@RestController
@RequestMapping("/property")
public class PropertyController {

    @Autowired
    PropertyService propertyService;

    // 增
    @PostMapping("/addProperty")
    public Result add(@RequestBody Property property){
        log.info("add:{}",property);
        propertyService.save(property);
        return Result.success();
    }

    // 查
    @GetMapping("/propertyList")
    public Result<List<Property>> get(){
        log.info("get");
        List<Property> list = propertyService.list();
        return Result.success(list);
    }

    @GetMapping("/propertyList/{id}")
    public Result<Property> getbyid(@PathVariable Long id){
        log.info("getbyid:{}",id);
        Property property = propertyService.getById(id);
        return Result.success(property);
    }


    // 删
    @DeleteMapping("/delProperty/{id}")
    public Result delete(@PathVariable Long id){
        log.info("delete:{}",id);
        propertyService.removeById(id);
        return Result.success();
    }

    // 改
    @PutMapping("/updateProperty")
    public Result update(@RequestBody Property property){
        log.info("update:{}",property);
        propertyService.updateById(property);
        return Result.success();
    }

}

